package com.ruoyi.web.controller.construction;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.construction.WordMark;
import com.ruoyi.system.service.construction.WordMarkService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 字体Controller
 * 
 * @author 张少丛
 * @date 2020-11-04
 */
@RestController
@RequestMapping("/construction/mark")
public class WordMarkController extends BaseController
{
    @Autowired
    private WordMarkService wordMarkService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询字体列表
     */
    @PreAuthorize("@ss.hasPermi('construction:mark:list')")
    @GetMapping("/list")
    public TableDataInfo list(WordMark wordMark)
    {
        startPage();
        // 获取登录用户ID
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        List<WordMark> list = wordMarkService.selectWordMarkList(wordMark,userId);
        return getDataTable(list);
    }

    /**
     * 导出字体列表
     */
    @PreAuthorize("@ss.hasPermi('construction:mark:export')")
    @Log(title = "字体", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WordMark wordMark)
    {
        // 获取登录用户ID
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        List<WordMark> list = wordMarkService.selectWordMarkList(wordMark,userId);
        ExcelUtil<WordMark> util = new ExcelUtil<WordMark>(WordMark.class);
        return util.exportExcel(list, "mark");
    }

    /**
     * 获取字体详细信息
     */
    @PreAuthorize("@ss.hasPermi('construction:mark:query')")
    @GetMapping(value = "/{wordId}")
    public AjaxResult getInfo(@PathVariable("wordId") Integer wordId)
    {
        return AjaxResult.success(wordMarkService.selectWordMarkById(wordId));
    }

    /**
     * 新增字体
     */
    @PreAuthorize("@ss.hasPermi('construction:mark:add')")
    @Log(title = "字体", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WordMark wordMark)
    {
        return toAjax(wordMarkService.insertWordMark(wordMark));
    }

    /**
     * 修改字体
     */
    @PreAuthorize("@ss.hasPermi('construction:mark:edit')")
    @Log(title = "字体", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WordMark wordMark)
    {
        return toAjax(wordMarkService.updateWordMark(wordMark));
    }

    /**
     * 删除字体
     */
    @PreAuthorize("@ss.hasPermi('construction:mark:remove')")
    @Log(title = "字体", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wordIds}")
    public AjaxResult remove(@PathVariable Integer[] wordIds)
    {
        return toAjax(wordMarkService.deleteWordMarkByIds(wordIds));
    }


    /**
     * 获取字体详细信息
     */
    @PreAuthorize("@ss.hasPermi('construction:mark:query')")
    @GetMapping(value = "/selectConstructionInfo")
    public AjaxResult selectConstructionInfo()
    {
        // 获取登录用户ID
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        return AjaxResult.success(wordMarkService.selectConstructionInfo(userId));
    }
}
